package com.yd.happyspine.ui.main.activity;


import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.view.animation.AccelerateInterpolator;
import android.widget.TextView;

import com.jaydenxiao.common.base.BaseActivity;
import com.jaydenxiao.common.commonutils.SPUtils;
import com.yd.happyspine.R;

import butterknife.Bind;

public class SplashActivity extends BaseActivity {
    @Bind(R.id.Splash)
    TextView Splash;

    @Override
    public int getLayoutId() {
        return R.layout.activity_splan;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void initView() {
        initAnimator();

    }

    private void initAnimator() {
        ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(Splash);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(objectAnimator);
        animatorSet.setInterpolator(new AccelerateInterpolator());
        animatorSet.setDuration(2000);
        animatorSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                String token = SPUtils.getSharedStringData(SplashActivity.this, "token");
              if (token.isEmpty()) {
                   startActivity(new Intent(SplashActivity.this, LoginActivity.class));
                   finish();
                } else {
                    startActivity(new Intent(SplashActivity.this, HomeActivity.class));
                    finish();
                }

            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animatorSet.start();
    }
}
